#include "kdcapplicationinterfaceimpl.h"

#include <QDir>
#include <KApplication>
#include <kdclib.h>
#include <KTempDir>

KDCApplicationInterfaceImpl::KDCApplicationInterfaceImpl() : KDCApplicationInterface()
{
	KTempDir tmp;
	tmp.setAutoRemove( false );
	pAppsTempPath = tmp.name();
	if ( pAppsTempPath.endsWith( '/' ) )
		pAppsTempPath.resize( pAppsTempPath.size() - 1 );
	pAppsLogFileName = pAppsTempPath + "/kdclog.log";
}

KDCApplicationInterfaceImpl::~KDCApplicationInterfaceImpl()
{
	removeDirectory( appTempPath() );
}

QString KDCApplicationInterfaceImpl::logFileName() const
{
	return pAppsLogFileName;
}

void KDCApplicationInterfaceImpl::writeLogMessage( const char *aMsg )
{
	writeToFile( logFileName(), aMsg );
}

KIcon KDCApplicationInterfaceImpl::appIcon() const
{
	return KIcon("media-optical");
}

QString KDCApplicationInterfaceImpl::appTempPath() const
{
	return pAppsTempPath;
}

QString KDCApplicationInterfaceImpl::applicationDirPath() const
{
	QDir dir( KApplication::applicationDirPath() );
	dir.cdUp();
	return dir.absolutePath();
}

QString KDCApplicationInterfaceImpl::applicationDataDir() const
{
	QDir dir ( KApplication::applicationDirPath() );
	dir.cdUp();
	dir.cd( "data" );
	return dir.absolutePath();
}

QString KDCApplicationInterfaceImpl::discDir( KDCDisc *aDisc ) const
{
	if ( !isNull( aDisc ) )
		return QString( appTempPath() + "/disc_%1" ).arg( aDisc->id() );
	return QString();
}

QString KDCApplicationInterfaceImpl::discOutDir( KDCDisc *aDisc ) const
{
	if ( !isNull( aDisc ) )
		return aDisc->settings()->outputPath() + QString( "/disc_%1" ).arg( aDisc->id() );
	return QString();
}

QString KDCApplicationInterfaceImpl::discConfigFile( KDCDisc *aDisc ) const
{
	if ( !isNull( aDisc ) )
		return QString( discDir( aDisc ) + "/discconfigfile.xml" );
	return QString();
}
